using System;
using Server;
using Server.Gumps;
using Server.Misc;
using Server.Items;
using Server.Network;
using Server.Mobiles;

namespace Server.Gumps
{
    public class ToTAdminGump : Gump
    {
        private Item m_Stone;

        private int m_ToTEras;
        private static string[] m_ToTInfo = 
		{
			//Opening Message
			"<center>Treasures of Tokuno Admin</center><br>" +
			"-Use the gems to switch eras<br>" +
			"-Drop era and Reward era can be changed seperately<br>" +
			"-Drop era can be deactivated, Reward era is always activated",
			//Treasures of Tokuno 1 message
			"<center>Treasures of Tokuno 1</center><br>" +
			"-10 charge Bleach Pigment can drop as a Lesser Artifact<br>" +
			"-50 charge Neon Pigments available as a reward<br>",
			//Treasures of Tokuno 2 message
			"<center>Treasures of Tokuno 2</center><br>" +
			"-30 types of 1 charge Metallic Pigments drop as Lesser Artifacts<br>" +
			"-1 charge Bleach Pigment can drop as a Lesser Artifact<br>" +
			"-10 charge Greater Metallic Pigments available as a reward",
			//Treasures of Tokuno 3 message
			"<center>Treasures of Tokuno 3</center><br>" +
			"-10 types of 1 charge Fresh Pigments drop as Lesser Artifacts<br>" +
			"-1 charge Bleach Pigment can drop as a Lesser Artifact<br>" +
			"-Leurocian's Mempo Of Fortune can drop as a Lesser Artifact"
		};

        public ToTAdminGump(Item stone)
            : base(30, 50)
        {
            m_Stone = stone;

            Closable = true;
            Disposable = true;
            Dragable = true;
            Resizable = false;

            m_ToTEras = Enum.GetValues(typeof(TreasuresOfTokunoEra)).Length - 1;

            AddPage(0);
            AddBackground(0, 0, 320, 75 + (m_ToTEras * 25), 9200);
            AddImageTiled(25, 18, 270, 10, 9267);
            AddLabel(75, 5, 54, "Treasures of Tokuno Admin");
            AddLabel(10, 25, 54, "ToT Era");
            AddLabel(90, 25, 54, "Drop Era");
            AddLabel(195, 25, 54, "Reward Era");
            AddLabel(287, 25, 54, "Info");

            AddBackground(320, 0, 200, 150, 9200);
            AddImageTiled(325, 5, 190, 140, 2624);
            AddAlphaRegion(325, 5, 190, 140);

            SetupToTEras();
        }

        public void SetupToTEras()
        {
            bool isActivated = TreasuresOfTokuno.DropEra != TreasuresOfTokunoEra.None;
            AddButton(75, 50, isActivated ? 2361 : 2360, isActivated ? 2361 : 2360, 1, GumpButtonType.Reply, 0);
            AddLabel(90, 45, isActivated ? 167 : 137, isActivated ? "Activated" : "Deactivated");

            for (int i = 0; i < m_ToTEras; i++)
            {
                int yoffset = (i * 25);

                bool isThisDropEra = ((int)TreasuresOfTokuno.DropEra - 1) == i;
                bool isThisRewardEra = ((int)TreasuresOfTokuno.RewardEra - 1) == i;
                int dropButtonID = isThisDropEra ? 2361 : 2360;
                int rewardButtonID = isThisRewardEra ? 2361 : 2360;

                AddLabel(10, 70 + yoffset, 2100, "ToT " + (i + 1));
                AddButton(75, 75 + yoffset, dropButtonID, dropButtonID, 2 + (i * 2), GumpButtonType.Reply, 0);
                AddLabel(90, 70 + yoffset, isThisDropEra ? 167 : 137, isThisDropEra ? "Active" : "Inactive");
                AddButton(180, 75 + yoffset, rewardButtonID, rewardButtonID, 2 + (i * 2) + 1, GumpButtonType.Reply, 0);
                AddLabel(195, 70 + yoffset, isThisRewardEra ? 167 : 137, isThisRewardEra ? "Active" : "Inactive");

                AddButton(285, 70 + yoffset, 4005, 4006, i, GumpButtonType.Page, 2 + i);
            }

            for (int i = 0; i < m_ToTInfo.Length; i++)
            {
                AddPage(1 + i);
                AddHtml(330, 10, 180, 130, m_ToTInfo[i], false, true);
            }
        }

        public override void OnResponse(NetState sender, RelayInfo info)
        {
            int button = info.ButtonID;
            Mobile from = sender.Mobile;

            bool isDropButton = button % 2 == 1;

            if (button == 1)
            {
                if (from.AccessLevel <= AccessLevel.Seer)
                {
                    from.SendMessage("Sorry you cannot do that!");
                }
                else
                {
                    TreasuresOfTokuno.DropEra = TreasuresOfTokunoEra.None;
                    World.Broadcast(0x35, true, "Treasures of Tokuno Drops have been deactivated");

                    m_Stone.Name = "Treasures of Tokuno Drops have been deactivated.";
                }
            }
            else if (button >= 2)
            {
                int selectedToT;
                if (button % 2 == 0)
                {
                    if (from.AccessLevel <= AccessLevel.Seer)
                    {
                        from.SendMessage("Sorry you cannot do that!");
                    }
                    else
                    {
                        selectedToT = button / 2;
                        TreasuresOfTokuno.DropEra = (TreasuresOfTokunoEra)(selectedToT);
                        m_Stone.Name = "Treasures of Tokuno " + selectedToT + " Drops have been enabled.";
                        from.SendMessage("Treasures of Tokuno " + selectedToT + " Drops have been enabled");
                    }
                }
                else
                {
                    if (from.AccessLevel <= AccessLevel.Seer)
                    {
                        from.SendMessage("Sorry you cannot do that!");
                    }
                    else
                    {
                        selectedToT = (button - 1) / 2;
                        TreasuresOfTokuno.RewardEra = (TreasuresOfTokunoEra)(selectedToT);
                        from.SendMessage("Treasures of Tokuno " + selectedToT + " Rewards have been enabled");
                    }
                }
            }
        }
    }

    public class ToTStone : Item
    {
        [Constructable]
        public ToTStone()
            : base(0xED8)
        {

            if (Check()) // Checks to see if there is a ToTStone already in the world.
            {
                World.Broadcast(0x35, true, "A Treasures of Tokuno Stone exist in the world !"); // You can remove this line so it won't say anything over global chat.
                Delete();
                return;
            }
            Name = "Treasures of Tokuno Stone.";

            Movable = false;
            Visible = true; // Set this line to false if you don't want players to see it.
            Hue = 0xB90;  // Alabaster Marble 1 hue.  Just for looks.
        }

        private bool Check()
        {
            foreach (Item item in World.Items.Values)
            {
                if (item is ToTStone && !item.Deleted && item != this)
                    return true;
            }
            return false;
        }

        public override void OnDoubleClick(Mobile from)
        {
            from.SendGump(new ToTAdminGump(this));
        }

        public ToTStone(Serial serial)
            : base(serial)
        {
        }

        public override void Serialize(GenericWriter writer)
        {
            base.Serialize(writer);
            writer.Write((int)0); // version
        }

        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);
            int version = reader.ReadInt();
        }
    }
}